package com.itheima.反射.field.demo1;

import java.lang.reflect.Field;

public class demo {
    public static void main(String[] args) throws NoSuchFieldException {
        //获取字节码文件对象
        Class clazz = Student.class;

        //获取所有public属性
        Field[] fields = clazz.getFields();
        for (Field field : fields) {
            System.out.println(field);
        }

        System.out.println("======================================================");
        //获取所有属性
        Field[] declaredFields = clazz.getDeclaredFields();
        for (Field declaredField : declaredFields) {
            System.out.println(declaredField);
        }
        System.out.println("======================================================");
        //获取某个public属性
        Field field = clazz.getField("name");
        System.out.println("field = " + field);
        System.out.println("======================================================");
        //获取某个属性
        Field declaredField = clazz.getDeclaredField("money");
        System.out.println("declaredField = " + declaredField);
    }
}
